package com.example.sb.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author kedong.lin
 */
public class MyInterceptor2 implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("拦截器名称+【"+this.getClass().getSimpleName()+"】");
        System.out.println("在方法执行之前");
       /* response.setStatus(500);
        response.setContentType("application/json;charset=utf-8");
        try(PrintWriter writer = response.getWriter()){
            writer.println("测试错误");
        }catch (Exception e){
            e.printStackTrace();
        }*/
        return false;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("拦截器名称+【"+this.getClass().getSimpleName()+"】");
        System.out.println("在方法执行之后");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("拦截器名称+【"+this.getClass().getSimpleName()+"】");
        System.out.println("完成视图渲染");
    }
}
